import ST from './lib/shell';
(async () => {
  console.log("Hololive!!!");
  ST.shellSync("kill -9 $(ps -ef|grep ffmpeg|grep -v grep|awk '{print $2}')");
  let promises = [
    'video0',
    'video2', // ?
    'video4',
    'video6',
    'video8',
    // 'video10',
    // 'video12',
    // 'video14',
    'video16', // ?
    'video18',
    'video20',
    'video22' // ?
  ].map(name => async () => {
    const cst = ST.getFrokShellTool();
    let bool = false;
    // const timmer = setTimeout(( ) => bool ? null : cst.exit() ,20000);
    const runRes = await cst.shellSync(`ffmpeg -f video4linux2 -t 5s -s 640x480 -pixel_format yuyv422 -i /dev/${name} ${name}.mp4 -y`);
    if (runRes.error) console.log("Error: ", (runRes.error as Error).message);
    // timmer.unref();
    cst.exit();
  });
  for (let i = 0; i < promises.length; i++) {
    await promises[i]();
  }
  // await Promise.all(promises);
  ST.shellSync("kill -9 $(ps -ef|grep ffmpeg|grep -v grep|awk '{print $2}')");
  console.log("Down");
})();